# set working directory#
data <- read.csv("second pilot - emotional intelligence test - data.csv", header=TRUE, stringsAsFactors = FALSE)

library(effects)
library(psych)
library(multicon)

## coding for emotional intelligence test ####

data$era1<- NA; data$era1[data$eraitem1==6] <- 1; data$era1[data$eraitem1!=6] <- 0
data$era2<- NA; data$era2[data$eraitem2==3] <- 1; data$era2[data$eraitem2!=3] <- 0
data$era3<- NA; data$era3[data$eraitem3==2] <- 1; data$era3[data$eraitem3!=2] <- 0
data$era4<- NA; data$era4[data$eraitem4==6] <- 1; data$era4[data$eraitem4!=6] <- 0
data$era5<- NA; data$era5[data$eraitem5==1] <- 1; data$era5[data$eraitem5!=1] <- 0
data$era6<- NA; data$era6[data$eraitem6==4] <- 1; data$era6[data$eraitem6!=4] <- 0
data$era7<- NA; data$era7[data$eraitem7==6] <- 1; data$era7[data$eraitem7!=6] <- 0
data$era8<- NA; data$era8[data$eraitem8==1] <- 1; data$era8[data$eraitem8!=1] <- 0
data$era9<- NA; data$era9[data$eraitem9==6] <- 1; data$era9[data$eraitem9!=6] <- 0
data$era10<- NA; data$era10[data$eraitem10==5] <- 1; data$era10[data$eraitem10!=5] <- 0
data$era11<- NA; data$era11[data$eraitem11==4] <- 1; data$era11[data$eraitem11!=4] <- 0
data$era12<- NA; data$era12[data$eraitem12==3] <- 1; data$era12[data$eraitem12!=3] <- 0
data$era13<- NA; data$era13[data$eraitem13==4] <- 1; data$era13[data$eraitem13!=4] <- 0
data$era14<- NA; data$era14[data$eraitem14==1] <- 1; data$era14[data$eraitem14!=1] <- 0
data$era15<- NA; data$era15[data$eraitem15==3] <- 1; data$era15[data$eraitem15!=3] <- 0
data$era16<- NA; data$era16[data$eraitem16==1] <- 1; data$era16[data$eraitem16!=1] <- 0
data$era17<- NA; data$era17[data$eraitem17==2] <- 1; data$era17[data$eraitem17!=2] <- 0
data$era18<- NA; data$era18[data$eraitem18==5] <- 1; data$era18[data$eraitem18!=5] <- 0
data$era19<- NA; data$era19[data$eraitem19==1] <- 1; data$era19[data$eraitem19!=1] <- 0
data$era20<- NA; data$era20[data$eraitem20==5] <- 1; data$era20[data$eraitem20!=5] <- 0
data$era21<- NA; data$era21[data$eraitem21==4] <- 1; data$era21[data$eraitem21!=4] <- 0
data$era22<- NA; data$era22[data$eraitem22==5] <- 1; data$era22[data$eraitem22!=5] <- 0
data$era23<- NA; data$era23[data$eraitem23==3] <- 1; data$era23[data$eraitem23!=3] <- 0
data$era24<- NA; data$era24[data$eraitem24==4] <- 1; data$era24[data$eraitem24!=4] <- 0
data$era25<- NA; data$era25[data$eraitem25==3] <- 1; data$era25[data$eraitem25!=3] <- 0
data$era26<- NA; data$era26[data$eraitem26==5] <- 1; data$era26[data$eraitem26!=5] <- 0
data$era27<- NA; data$era27[data$eraitem27==4] <- 1; data$era27[data$eraitem27!=4] <- 0
data$era28<- NA; data$era28[data$eraitem28==1] <- 1; data$era28[data$eraitem28!=1] <- 0
data$era29<- NA; data$era29[data$eraitem29==6] <- 1; data$era29[data$eraitem29!=6] <- 0
data$era30<- NA; data$era30[data$eraitem30==1] <- 1; data$era30[data$eraitem30!=1] <- 0
data$era31<- NA; data$era31[data$eraitem31==3] <- 1; data$era31[data$eraitem31!=3] <- 0
data$era32<- NA; data$era32[data$eraitem32==2] <- 1; data$era32[data$eraitem32!=2] <- 0
data$era33<- NA; data$era33[data$eraitem33==4] <- 1; data$era33[data$eraitem33!=4] <- 0
data$era34<- NA; data$era34[data$eraitem34==2] <- 1; data$era34[data$eraitem34!=2] <- 0
data$era35<- NA; data$era35[data$eraitem35==5] <- 1; data$era35[data$eraitem35!=5] <- 0
data$era36<- NA; data$era36[data$eraitem36==6] <- 1; data$era36[data$eraitem36!=6] <- 0
data$era37<- NA; data$era37[data$eraitem37==2] <- 1; data$era37[data$eraitem37!=2] <- 0
data$era38<- NA; data$era38[data$eraitem38==4] <- 1; data$era38[data$eraitem38!=4] <- 0
data$era39<- NA; data$era39[data$eraitem39==4] <- 1; data$era39[data$eraitem39!=4] <- 0
data$era40<- NA; data$era40[data$eraitem40==5] <- 1; data$era40[data$eraitem40!=5] <- 0
data$era41<- NA; data$era41[data$eraitem41==2] <- 1; data$era41[data$eraitem41!=2] <- 0
data$era42<- NA; data$era42[data$eraitem42==6] <- 1; data$era42[data$eraitem42!=6] <- 0
data$era43<- NA; data$era43[data$eraitem43==3] <- 1; data$era43[data$eraitem43!=3] <- 0
data$era44<- NA; data$era44[data$eraitem44==5] <- 1; data$era44[data$eraitem44!=5] <- 0
data$era45<- NA; data$era45[data$eraitem45==2] <- 1; data$era45[data$eraitem45!=2] <- 0
data$era46<- NA; data$era46[data$eraitem46==6] <- 1; data$era46[data$eraitem46!=6] <- 0
data$era47<- NA; data$era47[data$eraitem47==5] <- 1; data$era47[data$eraitem47!=5] <- 0
data$era48<- NA; data$era48[data$eraitem48==1] <- 1; data$era48[data$eraitem48!=1] <- 0
data$era49<- NA; data$era49[data$eraitem49==3] <- 1; data$era49[data$eraitem49!=3] <- 0
data$era50<- NA; data$era50[data$eraitem50==1] <- 1; data$era50[data$eraitem50!=1] <- 0
data$era51<- NA; data$era51[data$eraitem51==5] <- 1; data$era51[data$eraitem51!=5] <- 0
data$era52<- NA; data$era52[data$eraitem52==1] <- 1; data$era52[data$eraitem52!=1] <- 0
data$era53<- NA; data$era53[data$eraitem53==2] <- 1; data$era53[data$eraitem53!=2] <- 0
data$era54<- NA; data$era54[data$eraitem54==6] <- 1; data$era54[data$eraitem54!=6] <- 0
data$era55<- NA; data$era55[data$eraitem55==1] <- 1; data$era55[data$eraitem55!=1] <- 0
data$era56<- NA; data$era56[data$eraitem56==2] <- 1; data$era56[data$eraitem56!=2] <- 0
data$era57<- NA; data$era57[data$eraitem57==5] <- 1; data$era57[data$eraitem57!=5] <- 0
data$era58<- NA; data$era58[data$eraitem58==5] <- 1; data$era58[data$eraitem58!=5] <- 0
data$era59<- NA; data$era59[data$eraitem59==4] <- 1; data$era59[data$eraitem59!=4] <- 0
data$era60<- NA; data$era60[data$eraitem60==2] <- 1; data$era60[data$eraitem60!=2] <- 0
data$era61<- NA; data$era61[data$eraitem61==3] <- 1; data$era61[data$eraitem61!=3] <- 0
data$era62<- NA; data$era62[data$eraitem62==6] <- 1; data$era62[data$eraitem62!=6] <- 0
data$era63<- NA; data$era63[data$eraitem63==2] <- 1; data$era63[data$eraitem63!=2] <- 0
data$era64<- NA; data$era64[data$eraitem64==1] <- 1; data$era64[data$eraitem64!=1] <- 0
data$era65<- NA; data$era65[data$eraitem65==3] <- 1; data$era65[data$eraitem65!=3] <- 0
data$era66<- NA; data$era66[data$eraitem66==4] <- 1; data$era66[data$eraitem66!=4] <- 0
data$era67<- NA; data$era67[data$eraitem67==6] <- 1; data$era67[data$eraitem67!=6] <- 0
data$era68<- NA; data$era68[data$eraitem68==6] <- 1; data$era68[data$eraitem68!=6] <- 0
data$era69<- NA; data$era69[data$eraitem69==4] <- 1; data$era69[data$eraitem69!=4] <- 0
data$era70<- NA; data$era70[data$eraitem70==3] <- 1; data$era70[data$eraitem70!=3] <- 0
data$era71<- NA; data$era71[data$eraitem71==2] <- 1; data$era71[data$eraitem71!=2] <- 0
data$era72<- NA; data$era72[data$eraitem72==3] <- 1; data$era72[data$eraitem72!=3] <- 0

# count number of items attempted #
data$item1attempted <- NA; data$item1attempted[data$eraitem1>0] <- 1;
data$item2attempted <- NA; data$item2attempted[data$eraitem2>0] <- 1;
data$item3attempted <- NA; data$item3attempted[data$eraitem3>0] <- 1;
data$item4attempted <- NA; data$item4attempted[data$eraitem4>0] <- 1;
data$item5attempted <- NA; data$item5attempted[data$eraitem5>0] <- 1;
data$item6attempted <- NA; data$item6attempted[data$eraitem6>0] <- 1;
data$item7attempted <- NA; data$item7attempted[data$eraitem7>0] <- 1;
data$item8attempted <- NA; data$item8attempted[data$eraitem8>0] <- 1;
data$item9attempted <- NA; data$item9attempted[data$eraitem9>0] <- 1;
data$item10attempted <- NA; data$item10attempted[data$eraitem10>0] <- 1;
data$item11attempted <- NA; data$item11attempted[data$eraitem11>0] <- 1;
data$item12attempted <- NA; data$item12attempted[data$eraitem12>0] <- 1;
data$item13attempted <- NA; data$item13attempted[data$eraitem13>0] <- 1;
data$item14attempted <- NA; data$item14attempted[data$eraitem14>0] <- 1;
data$item15attempted <- NA; data$item15attempted[data$eraitem15>0] <- 1;
data$item16attempted <- NA; data$item16attempted[data$eraitem16>0] <- 1;
data$item17attempted <- NA; data$item17attempted[data$eraitem17>0] <- 1;
data$item18attempted <- NA; data$item18attempted[data$eraitem18>0] <- 1;
data$item19attempted <- NA; data$item19attempted[data$eraitem19>0] <- 1;
data$item20attempted <- NA; data$item20attempted[data$eraitem20>0] <- 1;
data$item21attempted <- NA; data$item21attempted[data$eraitem21>0] <- 1;
data$item22attempted <- NA; data$item22attempted[data$eraitem22>0] <- 1;
data$item23attempted <- NA; data$item23attempted[data$eraitem23>0] <- 1;
data$item24attempted <- NA; data$item24attempted[data$eraitem24>0] <- 1;
data$item25attempted <- NA; data$item25attempted[data$eraitem25>0] <- 1;
data$item26attempted <- NA; data$item26attempted[data$eraitem26>0] <- 1;
data$item27attempted <- NA; data$item27attempted[data$eraitem27>0] <- 1;
data$item28attempted <- NA; data$item28attempted[data$eraitem28>0] <- 1;
data$item29attempted <- NA; data$item29attempted[data$eraitem29>0] <- 1;
data$item30attempted <- NA; data$item30attempted[data$eraitem30>0] <- 1;
data$item31attempted <- NA; data$item31attempted[data$eraitem31>0] <- 1;
data$item32attempted <- NA; data$item32attempted[data$eraitem32>0] <- 1;
data$item33attempted <- NA; data$item33attempted[data$eraitem33>0] <- 1;
data$item34attempted <- NA; data$item34attempted[data$eraitem34>0] <- 1;
data$item35attempted <- NA; data$item35attempted[data$eraitem35>0] <- 1;
data$item36attempted <- NA; data$item36attempted[data$eraitem36>0] <- 1;
data$item37attempted <- NA; data$item37attempted[data$eraitem37>0] <- 1;
data$item38attempted <- NA; data$item38attempted[data$eraitem38>0] <- 1;
data$item39attempted <- NA; data$item39attempted[data$eraitem39>0] <- 1;
data$item40attempted <- NA; data$item40attempted[data$eraitem40>0] <- 1;
data$item41attempted <- NA; data$item41attempted[data$eraitem41>0] <- 1;
data$item42attempted <- NA; data$item42attempted[data$eraitem42>0] <- 1;
data$item43attempted <- NA; data$item43attempted[data$eraitem43>0] <- 1;
data$item44attempted <- NA; data$item44attempted[data$eraitem44>0] <- 1;
data$item45attempted <- NA; data$item45attempted[data$eraitem45>0] <- 1;
data$item46attempted <- NA; data$item46attempted[data$eraitem46>0] <- 1;
data$item47attempted <- NA; data$item47attempted[data$eraitem47>0] <- 1;
data$item48attempted <- NA; data$item48attempted[data$eraitem48>0] <- 1;
data$item49attempted <- NA; data$item49attempted[data$eraitem49>0] <- 1;
data$item50attempted <- NA; data$item50attempted[data$eraitem50>0] <- 1;
data$item51attempted <- NA; data$item51attempted[data$eraitem51>0] <- 1;
data$item52attempted <- NA; data$item52attempted[data$eraitem52>0] <- 1;
data$item53attempted <- NA; data$item53attempted[data$eraitem53>0] <- 1;
data$item54attempted <- NA; data$item54attempted[data$eraitem54>0] <- 1;
data$item55attempted <- NA; data$item55attempted[data$eraitem55>0] <- 1;
data$item56attempted <- NA; data$item56attempted[data$eraitem56>0] <- 1;
data$item57attempted <- NA; data$item57attempted[data$eraitem57>0] <- 1;
data$item58attempted <- NA; data$item58attempted[data$eraitem58>0] <- 1;
data$item59attempted <- NA; data$item59attempted[data$eraitem59>0] <- 1;
data$item60attempted <- NA; data$item60attempted[data$eraitem60>0] <- 1;
data$item61attempted <- NA; data$item61attempted[data$eraitem61>0] <- 1;
data$item62attempted <- NA; data$item62attempted[data$eraitem62>0] <- 1;
data$item63attempted <- NA; data$item63attempted[data$eraitem63>0] <- 1;
data$item64attempted <- NA; data$item64attempted[data$eraitem64>0] <- 1;
data$item65attempted <- NA; data$item65attempted[data$eraitem65>0] <- 1;
data$item66attempted <- NA; data$item66attempted[data$eraitem66>0] <- 1;
data$item67attempted <- NA; data$item67attempted[data$eraitem67>0] <- 1;
data$item68attempted <- NA; data$item68attempted[data$eraitem68>0] <- 1;
data$item69attempted <- NA; data$item69attempted[data$eraitem69>0] <- 1;
data$item70attempted <- NA; data$item70attempted[data$eraitem70>0] <- 1;
data$item71attempted <- NA; data$item71attempted[data$eraitem71>0] <- 1;
data$item72attempted <- NA; data$item72attempted[data$eraitem72>0] <- 1;

# create a table displaying how many items people attempted #
data$ERAtotalattempted<- with(data, (rowSums(cbind(item1attempted,item2attempted,item3attempted,item4attempted,item5attempted,item6attempted,item7attempted,item8attempted,item9attempted,item10attempted,item11attempted,item12attempted,item13attempted,item14attempted,item15attempted,item16attempted,item17attempted,item18attempted,item19attempted,item20attempted,item21attempted,item22attempted,item23attempted,item24attempted,item25attempted,item26attempted,item27attempted,item28attempted,item29attempted,item30attempted,item31attempted,item32attempted,item33attempted,item34attempted,item35attempted,item36attempted,item37attempted,item38attempted,item39attempted,item40attempted,item41attempted,item42attempted,item43attempted,item44attempted,item45attempted,item46attempted,item47attempted,item48attempted,item49attempted,item50attempted,item51attempted,item52attempted,item53attempted,item54attempted,item55attempted,item56attempted,item57attempted,item58attempted,item59attempted,item60attempted,item61attempted,item62attempted,item63attempted,item64attempted,item65attempted,item66attempted,item67attempted,item68attempted,item69attempted,item70attempted,item71attempted,item72attempted), na.rm=TRUE)))
table(data$ERAtotalattempted)

# create a data frame with those who attempted at least half of the items as per previous pre-registrations#
# note: all participants attempted all items
eraaccuracy <- subset(data, ERAtotalattempted>35)

# calculate total ERA total score and percent #
eraaccuracy$ERAtotal<- with(eraaccuracy, (rowSums(cbind(era1,era2,era3,era4,era5,era6,era7,era8,era9,era10,era11,era12,era13,era14,era15,era16,era17,era18,era19,era20,era21,era22,era23,era24,era25,era26,era27,era28,era29,era30,era31,era32,era33,era34,era35,era36,era37,era38,era39,era40,era41,era42,era43,era44,era45,era46,era47,era48,era49,era50,era51,era52,era53,era54,era55,era56,era57,era58,era59,era60,era61,era62,era63,era64,era65,era66,era67,era68,era69,era70,era71,era72), na.rm=TRUE)))
eraaccuracy$ERApercent <- eraaccuracy$ERAtotal/72

with(eraaccuracy, describe(cbind(ERApercent, ERAtotal,ERAtotalattempted)))

# alpha for the scale #
# error message  - alpha cannot be calculated #
with(eraaccuracy, alpha(data.frame(era1,era2,era3,era4,era5,era6,era7,era8,era9,era10,era11,era12,era13,era14,era15,era16,era17,era18,era19,era20,era21,era22,era23,era24,era25,era26,era27,era28,era29,era30,era31,era32,era33,era34,era35,era36,era37,era38,era39,era40,era41,era42,era43,era44,era45,era46,era47,era48,era49,era50,era51,era52,era53,era54,era55,era56,era57,era58,era59,era60,era61,era62,era63,era64,era65,era66,era67,era68,era69,era70,era71,era72), na.rm=TRUE))

# calculate split half reliability #
er.df <- with(eraaccuracy, data.frame(cbind(era1,era2,era3,era4,era5,era6,era7,era8,era9,era10,era11,era12,era13,era14,era15,era16,era17,era18,era19,era20,era21,era22,era23,era24,era25,era26,era27,era28,era29,era30,era31,era32,era33,era34,era35,era36,era37,era38,era39,era40,era41,era42,era43,era44,era45,era46,era47,era48,era49,era50,era51,era52,era53,era54,era55,era56,era57,era58,era59,era60,era61,era62,era63,era64,era65,era66,era67,era68,era69,era70,era71,era72)))
splithalf.r(er.df, sims = 1000, graph = TRUE)

# convert self rating from factor to NUMERIC #
eraaccuracy$ertselfrating<- as.numeric(eraaccuracy$ertselfrating)

# convert self rating to percentage
eraaccuracy$ertselfratingpercent <- eraaccuracy$ertselfrating/72

# descriptives of self rating and ERA test #
with(eraaccuracy, describe(cbind(ertselfrating,ertselfratingpercent,ERAtotal,ERApercent)))

# correlating EI test scores with self-assessed EI test scores #
with(eraaccuracy, cor.test(ERAtotal,ertselfrating))
xtabs(~ ERAtotal + ertselfrating, data = eraaccuracy)
xtabs(~ ertselfrating + ERAtotal, data = eraaccuracy)

# calculate the people who had accurate self-insight
eraaccuracy$overestimater <- NA; eraaccuracy$overestimater[eraaccuracy$ERAtotal<eraaccuracy$ertselfrating] <- 1; eraaccuracy$overestimater[eraaccuracy$ERAtotal>=eraaccuracy$ertselfrating] <- 0
eraaccuracy$underestimater <- NA; eraaccuracy$underestimater[eraaccuracy$ERAtotal>eraaccuracy$ertselfrating] <- 1; eraaccuracy$underestimater[eraaccuracy$ERAtotal<=eraaccuracy$ertselfrating] <- 0
eraaccuracy$accurate <- NA; eraaccuracy$accurate[eraaccuracy$ERAtotal==eraaccuracy$ertselfrating] <- 1; eraaccuracy$accurate[eraaccuracy$ERAtotal!=eraaccuracy$ertselfrating] <- 0

# dislay the people who were over- or under- or correct estimaters
xtabs(~ overestimater, data = eraaccuracy)
xtabs(~ underestimater, data = eraaccuracy)
xtabs(~ accurate, data = eraaccuracy)

## coding for cognitive intelligence test ####
## note: a large majority of respondents over-estimated their performance 
## this test is difficult and the average proportion of problems solved correctly is low (about 40%) 
## with this test there are not enough people with perfect self-insight or who under-estimate their performance to test our hypotheses
## therefore we conducted a second pilot test with another test of cognitive intelligence
## see separate data file and code for analyses of test of cognitive intelligence we will use in the main study

# test 1
eraaccuracy$cog1<- NA; eraaccuracy$cog1[eraaccuracy$Cog1==2] <- 1; eraaccuracy$cog1[eraaccuracy$Cog1!=2] <- 0
eraaccuracy$cog2<- NA; eraaccuracy$cog2[eraaccuracy$Cog2==3] <- 1; eraaccuracy$cog2[eraaccuracy$Cog2!=3] <- 0
eraaccuracy$cog3<- NA; eraaccuracy$cog3[eraaccuracy$Cog3==2] <- 1; eraaccuracy$cog3[eraaccuracy$Cog3!=2] <- 0
eraaccuracy$cog4<- NA; eraaccuracy$cog4[eraaccuracy$Cog4==4] <- 1; eraaccuracy$cog4[eraaccuracy$Cog4!=4] <- 0
eraaccuracy$cog5<- NA; eraaccuracy$cog5[eraaccuracy$Cog5==5] <- 1; eraaccuracy$cog5[eraaccuracy$Cog5!=5] <- 0
eraaccuracy$cog6<- NA; eraaccuracy$cog6[eraaccuracy$Cog6==2] <- 1; eraaccuracy$cog6[eraaccuracy$Cog6!=2] <- 0
eraaccuracy$cog7<- NA; eraaccuracy$cog7[eraaccuracy$Cog7==4] <- 1; eraaccuracy$cog7[eraaccuracy$Cog7!=4] <- 0
eraaccuracy$cog8<- NA; eraaccuracy$cog8[eraaccuracy$Cog8==2] <- 1; eraaccuracy$cog8[eraaccuracy$Cog8!=2] <- 0
eraaccuracy$cog9<- NA; eraaccuracy$cog9[eraaccuracy$Cog9==6] <- 1; eraaccuracy$cog9[eraaccuracy$Cog9!=6] <- 0
eraaccuracy$cog10<- NA; eraaccuracy$cog10[eraaccuracy$Cog10==3] <- 1; eraaccuracy$cog10[eraaccuracy$Cog10!=3] <- 0
eraaccuracy$cog11<- NA; eraaccuracy$cog11[eraaccuracy$Cog11==2] <- 1; eraaccuracy$cog11[eraaccuracy$Cog11!=2] <- 0
eraaccuracy$cog12<- NA; eraaccuracy$cog12[eraaccuracy$Cog12==2] <- 1; eraaccuracy$cog12[eraaccuracy$Cog12!=2] <- 0
eraaccuracy$cog13<- NA; eraaccuracy$cog13[eraaccuracy$Cogresp13==5] <- 1; eraaccuracy$cog13[eraaccuracy$Cogresp13!=5] <- 0

# split the two responses of test 2 into separate columns
library(reshape2)
split14 <- colsplit(eraaccuracy$Cog14, ",", c("Cog14_1","Cog14_2"))
split15 <- colsplit(eraaccuracy$Cog15, ",", c("Cog15_1","Cog15_2"))
split16 <- colsplit(eraaccuracy$Cog16, ",", c("Cog16_1","Cog16_2"))
split17 <- colsplit(eraaccuracy$Cog17, ",", c("Cog17_1","Cog17_2"))
split18 <- colsplit(eraaccuracy$Cog18, ",", c("Cog18_1","Cog18_2"))
split19 <- colsplit(eraaccuracy$Cog19, ",", c("Cog19_1","Cog19_2"))
split20 <- colsplit(eraaccuracy$Cog20, ",", c("Cog20_1","Cog20_2"))
split21 <- colsplit(eraaccuracy$Cog21, ",", c("Cog21_1","Cog21_2"))
split22 <- colsplit(eraaccuracy$Cog22, ",", c("Cog22_1","Cog22_2"))
split23 <- colsplit(eraaccuracy$Cog23, ",", c("Cog23_1","Cog23_2"))
split24 <- colsplit(eraaccuracy$Cog24, ",", c("Cog24_1","Cog24_2"))
split25 <- colsplit(eraaccuracy$Cog25, ",", c("Cog25_1","Cog25_2"))
split26 <- colsplit(eraaccuracy$Cog26, ",", c("Cog26_1","Cog26_2"))
split27 <- colsplit(eraaccuracy$Cog27, ",", c("Cog27_1","Cog27_2"))

eraaccuracy <- cbind(eraaccuracy, split14, split15, split16, split17, split18, split19, split20, split21, split22, split23, split24, split25, split26, split27)

# test 2 #
eraaccuracy$cog14<- NA; eraaccuracy$cog14[eraaccuracy$Cog14_1==2 & eraaccuracy$Cog14_2==5] <- 1;  eraaccuracy$cog14[eraaccuracy$Cog14_1!=2 | eraaccuracy$Cog14_2!=5] <- 0
eraaccuracy$cog15<- NA; eraaccuracy$cog15[eraaccuracy$Cog15_1==1 & eraaccuracy$Cog15_2==5] <- 1;  eraaccuracy$cog15[eraaccuracy$Cog15_1!=1 | eraaccuracy$Cog15_2!=5] <- 0
eraaccuracy$cog16<- NA; eraaccuracy$cog16[eraaccuracy$Cog16_1==1 & eraaccuracy$Cog16_2==4] <- 1;  eraaccuracy$cog16[eraaccuracy$Cog16_1!=1 | eraaccuracy$Cog16_2!=4] <- 0
eraaccuracy$cog17<- NA; eraaccuracy$cog17[eraaccuracy$Cog17_1==3 & eraaccuracy$Cog17_2==5] <- 1;  eraaccuracy$cog17[eraaccuracy$Cog17_1!=3 | eraaccuracy$Cog17_2!=5] <- 0
eraaccuracy$cog18<- NA; eraaccuracy$cog18[eraaccuracy$Cog18_1==2 & eraaccuracy$Cog18_2==5] <- 1;  eraaccuracy$cog18[eraaccuracy$Cog18_1!=2 | eraaccuracy$Cog18_2!=5] <- 0
eraaccuracy$cog19<- NA; eraaccuracy$cog19[eraaccuracy$Cog19_1==1 & eraaccuracy$Cog19_2==4] <- 1;  eraaccuracy$cog19[eraaccuracy$Cog19_1!=1 | eraaccuracy$Cog19_2!=4] <- 0
eraaccuracy$cog20<- NA; eraaccuracy$cog20[eraaccuracy$Cog20_1==2 & eraaccuracy$Cog20_2==5] <- 1;  eraaccuracy$cog20[eraaccuracy$Cog20_1!=2 | eraaccuracy$Cog20_2!=5] <- 0
eraaccuracy$cog21<- NA; eraaccuracy$cog21[eraaccuracy$Cog21_1==2 & eraaccuracy$Cog21_2==5] <- 1;  eraaccuracy$cog21[eraaccuracy$Cog21_1!=2 | eraaccuracy$Cog21_2!=5] <- 0
eraaccuracy$cog22<- NA; eraaccuracy$cog22[eraaccuracy$Cog22_1==1 & eraaccuracy$Cog22_2==4] <- 1;  eraaccuracy$cog22[eraaccuracy$Cog22_1!=1 | eraaccuracy$Cog22_2!=4] <- 0
eraaccuracy$cog23<- NA; eraaccuracy$cog23[eraaccuracy$Cog23_1==2 & eraaccuracy$Cog23_2==4] <- 1;  eraaccuracy$cog23[eraaccuracy$Cog23_1!=2 | eraaccuracy$Cog23_2!=4] <- 0
eraaccuracy$cog24<- NA; eraaccuracy$cog24[eraaccuracy$Cog24_1==1 & eraaccuracy$Cog24_2==5] <- 1;  eraaccuracy$cog24[eraaccuracy$Cog24_1!=1 | eraaccuracy$Cog24_2!=5] <- 0
eraaccuracy$cog25<- NA; eraaccuracy$cog25[eraaccuracy$Cog25_1==3 & eraaccuracy$Cog25_2==4] <- 1;  eraaccuracy$cog25[eraaccuracy$Cog25_1!=3 | eraaccuracy$Cog25_2!=4] <- 0
eraaccuracy$cog26<- NA; eraaccuracy$cog26[eraaccuracy$Cog26_1==2 & eraaccuracy$Cog26_2==3] <- 1;  eraaccuracy$cog26[eraaccuracy$Cog26_1!=2 | eraaccuracy$Cog26_2!=3] <- 0
eraaccuracy$cog27<- NA; eraaccuracy$cog27[eraaccuracy$Cog27_1==1 & eraaccuracy$Cog27_2==2] <- 1;  eraaccuracy$cog27[eraaccuracy$Cog27_1!=1 | eraaccuracy$Cog27_2!=2] <- 0

# test 3
eraaccuracy$cog28<- NA; eraaccuracy$cog28[eraaccuracy$Cog28==5] <- 1; eraaccuracy$cog28[eraaccuracy$Cog28!=5] <- 0
eraaccuracy$cog29<- NA; eraaccuracy$cog29[eraaccuracy$Cog29==5] <- 1; eraaccuracy$cog29[eraaccuracy$Cog29!=5] <- 0
eraaccuracy$cog30<- NA; eraaccuracy$cog30[eraaccuracy$Cog30==5] <- 1; eraaccuracy$cog30[eraaccuracy$Cog30!=5] <- 0
eraaccuracy$cog31<- NA; eraaccuracy$cog31[eraaccuracy$Cog31==2] <- 1; eraaccuracy$cog31[eraaccuracy$Cog31!=2] <- 0
eraaccuracy$cog32<- NA; eraaccuracy$cog32[eraaccuracy$Cog32==3] <- 1; eraaccuracy$cog32[eraaccuracy$Cog32!=3] <- 0
eraaccuracy$cog33<- NA; eraaccuracy$cog33[eraaccuracy$Cog33==4] <- 1; eraaccuracy$cog33[eraaccuracy$Cog33!=4] <- 0
eraaccuracy$cog34<- NA; eraaccuracy$cog34[eraaccuracy$Cog34==5] <- 1; eraaccuracy$cog34[eraaccuracy$Cog34!=5] <- 0
eraaccuracy$cog35<- NA; eraaccuracy$cog35[eraaccuracy$Cog35==5] <- 1; eraaccuracy$cog35[eraaccuracy$Cog35!=5] <- 0
eraaccuracy$cog36<- NA; eraaccuracy$cog36[eraaccuracy$Cog36==1] <- 1; eraaccuracy$cog36[eraaccuracy$Cog36!=1] <- 0
eraaccuracy$cog37<- NA; eraaccuracy$cog37[eraaccuracy$Cog37==1] <- 1; eraaccuracy$cog37[eraaccuracy$Cog37!=1] <- 0
eraaccuracy$cog38<- NA; eraaccuracy$cog38[eraaccuracy$Cog38==6] <- 1; eraaccuracy$cog38[eraaccuracy$Cog38!=6] <- 0
eraaccuracy$cog39<- NA; eraaccuracy$cog39[eraaccuracy$Cog39==3] <- 1; eraaccuracy$cog39[eraaccuracy$Cog39!=3] <- 0
eraaccuracy$cog40<- NA; eraaccuracy$cog40[eraaccuracy$Cog40==3] <- 1; eraaccuracy$cog40[eraaccuracy$Cog40!=3] <- 0

# test 4
eraaccuracy$cog41<- NA; eraaccuracy$cog41[eraaccuracy$Cog41==2] <- 1; eraaccuracy$cog41[eraaccuracy$Cog41!=2] <- 0
eraaccuracy$cog42<- NA; eraaccuracy$cog42[eraaccuracy$Cog42==1] <- 1; eraaccuracy$cog42[eraaccuracy$Cog42!=1] <- 0
eraaccuracy$cog43<- NA; eraaccuracy$cog43[eraaccuracy$Cog43==4] <- 1; eraaccuracy$cog43[eraaccuracy$Cog43!=4] <- 0
eraaccuracy$cog44<- NA; eraaccuracy$cog44[eraaccuracy$Cog44==4] <- 1; eraaccuracy$cog44[eraaccuracy$Cog44!=4] <- 0
eraaccuracy$cog45<- NA; eraaccuracy$cog45[eraaccuracy$Cog45==1] <- 1; eraaccuracy$cog45[eraaccuracy$Cog45!=1] <- 0
eraaccuracy$cog46<- NA; eraaccuracy$cog46[eraaccuracy$Cog46==2] <- 1; eraaccuracy$cog46[eraaccuracy$Cog46!=2] <- 0
eraaccuracy$cog47<- NA; eraaccuracy$cog47[eraaccuracy$Cog47==3] <- 1; eraaccuracy$cog47[eraaccuracy$Cog47!=3] <- 0
eraaccuracy$cog48<- NA; eraaccuracy$cog48[eraaccuracy$Cog48==4] <- 1; eraaccuracy$cog48[eraaccuracy$Cog48!=4] <- 0
eraaccuracy$cog49<- NA; eraaccuracy$cog49[eraaccuracy$Cog49==1] <- 1; eraaccuracy$cog49[eraaccuracy$Cog49!=1] <- 0
eraaccuracy$cog50<- NA; eraaccuracy$cog50[eraaccuracy$Cog50==4] <- 1; eraaccuracy$cog50[eraaccuracy$Cog50!=4] <- 0

# calculate total cog score #
eraaccuracy$cogtotal <- with(eraaccuracy, (rowSums(cbind(cog1,cog2,cog3,cog4,cog5,cog6,cog7,cog8,cog9,cog10,cog11,cog12,cog13,cog14,cog15,cog16,cog17,cog18,cog19,cog20,cog21,cog22,cog23,cog24,cog25,cog26,cog27,cog28,cog29,cog30,cog31,cog32,cog33,cog34,cog35,cog36,cog37,cog38,cog39,cog40,cog41,cog42,cog43,cog44,cog45,cog46,cog47,cog48,cog49,cog50), na.rm=TRUE)))
eraaccuracy$cogpercent <- eraaccuracy$cogtotal/50
with(eraaccuracy, describe(cbind(cogtotal,cogpercent)))
 
# calculate alpha #
with(eraaccuracy, alpha(data.frame(cog1,cog2,cog3,cog4,cog5,cog6,cog7,cog8,cog9,cog10,cog11,cog12,cog13,cog14,cog15,cog16,cog17,cog18,cog19,cog20,cog21,cog22,cog23,cog24,cog25,cog26,cog27,cog28,cog29,cog30,cog31,cog32,cog33,cog34,cog35,cog36,cog37,cog38,cog39,cog40,cog41,cog42,cog43,cog44,cog45,cog46,cog47,cog48,cog49,cog50), na.rm=TRUE))

# split half #
er.df <- with(eraaccuracy, data.frame(cbind(cog1,cog2,cog3,cog4,cog5,cog6,cog7,cog8,cog9,cog10,cog11,cog12,cog13,cog14,cog16,cog17,cog18,cog19,cog20,cog21,cog22,cog23,cog24,cog25,cog26,cog27,cog28,cog29,cog30,cog31,cog32,cog33,cog34,cog35,cog36,cog37,cog38,cog39,cog40,cog41,cog42,cog43,cog44,cog45,cog46,cog47,cog48,cog49,cog50), na.rm=TRUE))
splithalf.r(er.df, sims = 1000, graph = TRUE)

# count attempted cognitive questions
eraaccuracy$item1attempted.cog <- NA; eraaccuracy$item1attempted.cog[eraaccuracy$Cog1>0] <- 1;
eraaccuracy$item2attempted.cog <- NA; eraaccuracy$item2attempted.cog[eraaccuracy$Cog2>0] <- 1;
eraaccuracy$item3attempted.cog <- NA; eraaccuracy$item3attempted.cog[eraaccuracy$Cog3>0] <- 1;
eraaccuracy$item4attempted.cog <- NA; eraaccuracy$item4attempted.cog[eraaccuracy$Cog4>0] <- 1;
eraaccuracy$item5attempted.cog <- NA; eraaccuracy$item5attempted.cog[eraaccuracy$Cog5>0] <- 1;
eraaccuracy$item6attempted.cog <- NA; eraaccuracy$item6attempted.cog[eraaccuracy$Cog6>0] <- 1;
eraaccuracy$item7attempted.cog <- NA; eraaccuracy$item7attempted.cog[eraaccuracy$Cog7>0] <- 1;
eraaccuracy$item8attempted.cog <- NA; eraaccuracy$item8attempted.cog[eraaccuracy$Cog8>0] <- 1;
eraaccuracy$item9attempted.cog <- NA; eraaccuracy$item9attempted.cog[eraaccuracy$Cog9>0] <- 1;
eraaccuracy$item10attempted.cog <- NA; eraaccuracy$item10attempted.cog[eraaccuracy$Cog10>0] <- 1;
eraaccuracy$item11attempted.cog <- NA; eraaccuracy$item11attempted.cog[eraaccuracy$Cog11>0] <- 1;
eraaccuracy$item12attempted.cog <- NA; eraaccuracy$item12attempted.cog[eraaccuracy$Cog12>0] <- 1;
eraaccuracy$item13attempted.cog <- NA; eraaccuracy$item13attempted.cog[eraaccuracy$Cog13>0] <- 1;
eraaccuracy$item14attempted.cog <- NA; eraaccuracy$item14attempted.cog[eraaccuracy$Cog14>0] <- 1;
eraaccuracy$item15attempted.cog <- NA; eraaccuracy$item15attempted.cog[eraaccuracy$Cog15>0] <- 1;
eraaccuracy$item16attempted.cog <- NA; eraaccuracy$item16attempted.cog[eraaccuracy$Cog16>0] <- 1;
eraaccuracy$item17attempted.cog <- NA; eraaccuracy$item17attempted.cog[eraaccuracy$Cog17>0] <- 1;
eraaccuracy$item18attempted.cog <- NA; eraaccuracy$item18attempted.cog[eraaccuracy$Cog18>0] <- 1;
eraaccuracy$item19attempted.cog <- NA; eraaccuracy$item19attempted.cog[eraaccuracy$Cog19>0] <- 1;
eraaccuracy$item20attempted.cog <- NA; eraaccuracy$item20attempted.cog[eraaccuracy$Cog20>0] <- 1;
eraaccuracy$item21attempted.cog <- NA; eraaccuracy$item21attempted.cog[eraaccuracy$Cog21>0] <- 1;
eraaccuracy$item22attempted.cog <- NA; eraaccuracy$item22attempted.cog[eraaccuracy$Cog22>0] <- 1;
eraaccuracy$item23attempted.cog <- NA; eraaccuracy$item23attempted.cog[eraaccuracy$Cog23>0] <- 1;
eraaccuracy$item24attempted.cog <- NA; eraaccuracy$item24attempted.cog[eraaccuracy$Cog24>0] <- 1;
eraaccuracy$item25attempted.cog <- NA; eraaccuracy$item25attempted.cog[eraaccuracy$Cog25>0] <- 1;
eraaccuracy$item26attempted.cog <- NA; eraaccuracy$item26attempted.cog[eraaccuracy$Cog26>0] <- 1;
eraaccuracy$item27attempted.cog <- NA; eraaccuracy$item27attempted.cog[eraaccuracy$Cog27>0] <- 1;
eraaccuracy$item28attempted.cog <- NA; eraaccuracy$item28attempted.cog[eraaccuracy$Cog28>0] <- 1;
eraaccuracy$item29attempted.cog <- NA; eraaccuracy$item29attempted.cog[eraaccuracy$Cog29>0] <- 1;
eraaccuracy$item30attempted.cog <- NA; eraaccuracy$item30attempted.cog[eraaccuracy$Cog30>0] <- 1;
eraaccuracy$item31attempted.cog <- NA; eraaccuracy$item31attempted.cog[eraaccuracy$Cog31>0] <- 1;
eraaccuracy$item32attempted.cog <- NA; eraaccuracy$item32attempted.cog[eraaccuracy$Cog32>0] <- 1;
eraaccuracy$item33attempted.cog <- NA; eraaccuracy$item33attempted.cog[eraaccuracy$Cog33>0] <- 1;
eraaccuracy$item34attempted.cog <- NA; eraaccuracy$item34attempted.cog[eraaccuracy$Cog34>0] <- 1;
eraaccuracy$item35attempted.cog <- NA; eraaccuracy$item35attempted.cog[eraaccuracy$Cog35>0] <- 1;
eraaccuracy$item36attempted.cog <- NA; eraaccuracy$item36attempted.cog[eraaccuracy$Cog36>0] <- 1;
eraaccuracy$item37attempted.cog <- NA; eraaccuracy$item37attempted.cog[eraaccuracy$Cog37>0] <- 1;
eraaccuracy$item38attempted.cog <- NA; eraaccuracy$item38attempted.cog[eraaccuracy$Cog38>0] <- 1;
eraaccuracy$item39attempted.cog <- NA; eraaccuracy$item39attempted.cog[eraaccuracy$Cog39>0] <- 1;
eraaccuracy$item40attempted.cog <- NA; eraaccuracy$item40attempted.cog[eraaccuracy$Cog40>0] <- 1;
eraaccuracy$item41attempted.cog <- NA; eraaccuracy$item41attempted.cog[eraaccuracy$Cog41>0] <- 1;
eraaccuracy$item42attempted.cog <- NA; eraaccuracy$item42attempted.cog[eraaccuracy$Cog42>0] <- 1;
eraaccuracy$item43attempted.cog <- NA; eraaccuracy$item43attempted.cog[eraaccuracy$Cog43>0] <- 1;
eraaccuracy$item44attempted.cog <- NA; eraaccuracy$item44attempted.cog[eraaccuracy$Cog44>0] <- 1;
eraaccuracy$item45attempted.cog <- NA; eraaccuracy$item45attempted.cog[eraaccuracy$Cog45>0] <- 1;
eraaccuracy$item46attempted.cog <- NA; eraaccuracy$item46attempted.cog[eraaccuracy$Cog46>0] <- 1;
eraaccuracy$item47attempted.cog <- NA; eraaccuracy$item47attempted.cog[eraaccuracy$Cog47>0] <- 1;
eraaccuracy$item48attempted.cog <- NA; eraaccuracy$item48attempted.cog[eraaccuracy$Cog48>0] <- 1;
eraaccuracy$item49attempted.cog <- NA; eraaccuracy$item49attempted.cog[eraaccuracy$Cog49>0] <- 1;
eraaccuracy$item50attempted.cog <- NA; eraaccuracy$item50attempted.cog[eraaccuracy$Cog50>0] <- 1;

# count total attempted questions #
eraaccuracy$totalattempted.cog<- with(eraaccuracy, (rowSums(cbind(item1attempted.cog,item2attempted.cog,item3attempted.cog,item4attempted.cog,item5attempted.cog,item6attempted.cog,item7attempted.cog,item8attempted.cog,item9attempted.cog,item10attempted.cog,item11attempted.cog,item12attempted.cog,item13attempted.cog,item14attempted.cog,item15attempted.cog,item16attempted.cog,item17attempted.cog,item18attempted.cog,item19attempted.cog,item20attempted.cog,item21attempted.cog,item22attempted.cog,item23attempted.cog,item24attempted.cog,item25attempted.cog,item26attempted.cog,item27attempted.cog,item28attempted.cog,item29attempted.cog,item30attempted.cog,item31attempted.cog,item32attempted.cog,item33attempted.cog,item34attempted.cog,item35attempted.cog,item36attempted.cog,item37attempted.cog,item38attempted.cog,item39attempted.cog,item40attempted.cog,item41attempted.cog,item42attempted.cog,item43attempted.cog,item44attempted.cog,item45attempted.cog,item46attempted.cog,item47attempted.cog,item48attempted.cog,item49attempted.cog,item50attempted.cog), na.rm=TRUE)))
table(eraaccuracy$totalattempted.cog)

# subset people who did more than half the test #
cogaccuracy <- subset(eraaccuracy, totalattempted.cog>25)

# conver cog self rating from factor to numeric
cogaccuracy$cogselfrating <- as.numeric(cogaccuracy$cogselfrating)

# descriptives of cog self rating
with(cogaccuracy, describe(cbind(cogselfrating, cogtotal, ERAtotal, ertselfrating, ERApercent, cogpercent)))

# correlating cog test scores with self-assessed cog test scores #
with(cogaccuracy, corr.test(cbind(cogtotal, cogselfrating, ERAtotal,ertselfrating)))

# calculate the people who had accurate self-insight
cogaccuracy$overestimater <- NA; cogaccuracy$overestimater[cogaccuracy$cogtotal<cogaccuracy$cogselfrating] <- 1; cogaccuracy$overestimater[cogaccuracy$cogtotal>=cogaccuracy$cogselfrating] <- 0
cogaccuracy$underestimater <- NA; cogaccuracy$underestimater[cogaccuracy$cogtotal>cogaccuracy$cogselfrating] <- 1; cogaccuracy$underestimater[cogaccuracy$cogtotal<=cogaccuracy$cogselfrating] <- 0
cogaccuracy$accurate <- NA; cogaccuracy$accurate[cogaccuracy$cogtotal==cogaccuracy$cogselfrating] <- 1; cogaccuracy$accurate[cogaccuracy$cogtotal!=cogaccuracy$cogselfrating] <- 0

# dislay the people who were over- or under- or correct estimaters
xtabs(~ overestimater, data = cogaccuracy)
xtabs(~ underestimater, data = cogaccuracy)
xtabs(~ accurate, data = cogaccuracy)
with(cogaccuracy, describe(cbind(overestimater, underestimater, accurate)))

## coding for DANVA measure of emotion recognition test (to test convergent validity of measure we  will use in the main study) ####

eraaccuracy$danva1<- NA; eraaccuracy$danva1[eraaccuracy$DVresp1==1] <- 1; eraaccuracy$danva1[eraaccuracy$DVresp1!=1] <- 0
eraaccuracy$danva2<- NA; eraaccuracy$danva2[eraaccuracy$DVresp2==4] <- 1; eraaccuracy$danva2[eraaccuracy$DVresp2!=4] <- 0
eraaccuracy$danva3<- NA; eraaccuracy$danva3[eraaccuracy$DVresp3==3] <- 1; eraaccuracy$danva3[eraaccuracy$DVresp3!=3] <- 0
eraaccuracy$danva4<- NA; eraaccuracy$danva4[eraaccuracy$DVresp4==1] <- 1; eraaccuracy$danva4[eraaccuracy$DVresp4!=1] <- 0
eraaccuracy$danva5<- NA; eraaccuracy$danva5[eraaccuracy$DVresp5==3] <- 1; eraaccuracy$danva5[eraaccuracy$DVresp5!=3] <- 0
eraaccuracy$danva6<- NA; eraaccuracy$danva6[eraaccuracy$DVresp6==2] <- 1; eraaccuracy$danva6[eraaccuracy$DVresp6!=2] <- 0
eraaccuracy$danva7<- NA; eraaccuracy$danva7[eraaccuracy$DVresp7==1] <- 1; eraaccuracy$danva7[eraaccuracy$DVresp7!=1] <- 0
eraaccuracy$danva8<- NA; eraaccuracy$danva8[eraaccuracy$DVresp8==4] <- 1; eraaccuracy$danva8[eraaccuracy$DVresp8!=4] <- 0
eraaccuracy$danva9<- NA; eraaccuracy$danva9[eraaccuracy$DVresp9==4] <- 1; eraaccuracy$danva9[eraaccuracy$DVresp9!=4] <- 0
eraaccuracy$danva10<- NA; eraaccuracy$danva10[eraaccuracy$DVresp10==1] <- 1; eraaccuracy$danva10[eraaccuracy$DVresp10!=1] <- 0
eraaccuracy$danva11<- NA; eraaccuracy$danva11[eraaccuracy$DVresp11==2] <- 1; eraaccuracy$danva11[eraaccuracy$DVresp11!=2] <- 0
eraaccuracy$danva12<- NA; eraaccuracy$danva12[eraaccuracy$DVresp12==3] <- 1; eraaccuracy$danva12[eraaccuracy$DVresp12!=3] <- 0
eraaccuracy$danva13<- NA; eraaccuracy$danva13[eraaccuracy$DVresp13==2] <- 1; eraaccuracy$danva13[eraaccuracy$DVresp13!=2] <- 0
eraaccuracy$danva14<- NA; eraaccuracy$danva14[eraaccuracy$DVresp14==2] <- 1; eraaccuracy$danva14[eraaccuracy$DVresp14!=2] <- 0
eraaccuracy$danva15<- NA; eraaccuracy$danva15[eraaccuracy$DVresp15==3] <- 1; eraaccuracy$danva15[eraaccuracy$DVresp15!=3] <- 0
eraaccuracy$danva16<- NA; eraaccuracy$danva16[eraaccuracy$DVresp16==4] <- 1; eraaccuracy$danva16[eraaccuracy$DVresp16!=4] <- 0
eraaccuracy$danva17<- NA; eraaccuracy$danva17[eraaccuracy$DVresp17==2] <- 1; eraaccuracy$danva17[eraaccuracy$DVresp17!=2] <- 0
eraaccuracy$danva18<- NA; eraaccuracy$danva18[eraaccuracy$DVresp18==2] <- 1; eraaccuracy$danva18[eraaccuracy$DVresp18!=2] <- 0
eraaccuracy$danva19<- NA; eraaccuracy$danva19[eraaccuracy$DVresp19==4] <- 1; eraaccuracy$danva19[eraaccuracy$DVresp19!=4] <- 0
eraaccuracy$danva20<- NA; eraaccuracy$danva20[eraaccuracy$DVresp20==3] <- 1; eraaccuracy$danva20[eraaccuracy$DVresp20!=3] <- 0
eraaccuracy$danva21<- NA; eraaccuracy$danva21[eraaccuracy$DVresp21==4] <- 1; eraaccuracy$danva21[eraaccuracy$DVresp21!=4] <- 0
eraaccuracy$danva22<- NA; eraaccuracy$danva22[eraaccuracy$DVresp22==3] <- 1; eraaccuracy$danva22[eraaccuracy$DVresp22!=3] <- 0
eraaccuracy$danva23<- NA; eraaccuracy$danva23[eraaccuracy$DVresp23==1] <- 1; eraaccuracy$danva23[eraaccuracy$DVresp23!=1] <- 0
eraaccuracy$danva24<- NA; eraaccuracy$danva24[eraaccuracy$DVresp24==1] <- 1; eraaccuracy$danva24[eraaccuracy$DVresp24!=1] <- 0

# count items attempted
eraaccuracy$item1attempted.dv <- NA; eraaccuracy$item1attempted.dv[eraaccuracy$DVresp1>0] <- 1;
eraaccuracy$item2attempted.dv <- NA; eraaccuracy$item2attempted.dv[eraaccuracy$DVresp2>0] <- 1;
eraaccuracy$item3attempted.dv <- NA; eraaccuracy$item3attempted.dv[eraaccuracy$DVresp3>0] <- 1;
eraaccuracy$item4attempted.dv <- NA; eraaccuracy$item4attempted.dv[eraaccuracy$DVresp4>0] <- 1;
eraaccuracy$item5attempted.dv <- NA; eraaccuracy$item5attempted.dv[eraaccuracy$DVresp5>0] <- 1;
eraaccuracy$item6attempted.dv <- NA; eraaccuracy$item6attempted.dv[eraaccuracy$DVresp6>0] <- 1;
eraaccuracy$item7attempted.dv <- NA; eraaccuracy$item7attempted.dv[eraaccuracy$DVresp7>0] <- 1;
eraaccuracy$item8attempted.dv <- NA; eraaccuracy$item8attempted.dv[eraaccuracy$DVresp8>0] <- 1;
eraaccuracy$item9attempted.dv <- NA; eraaccuracy$item9attempted.dv[eraaccuracy$DVresp9>0] <- 1;
eraaccuracy$item10attempted.dv <- NA; eraaccuracy$item10attempted.dv[eraaccuracy$DVresp10>0] <- 1;
eraaccuracy$item11attempted.dv <- NA; eraaccuracy$item11attempted.dv[eraaccuracy$DVresp11>0] <- 1;
eraaccuracy$item12attempted.dv <- NA; eraaccuracy$item12attempted.dv[eraaccuracy$DVresp12>0] <- 1;
eraaccuracy$item13attempted.dv <- NA; eraaccuracy$item13attempted.dv[eraaccuracy$DVresp13>0] <- 1;
eraaccuracy$item14attempted.dv <- NA; eraaccuracy$item14attempted.dv[eraaccuracy$DVresp14>0] <- 1;
eraaccuracy$item15attempted.dv <- NA; eraaccuracy$item15attempted.dv[eraaccuracy$DVresp15>0] <- 1;
eraaccuracy$item16attempted.dv <- NA; eraaccuracy$item16attempted.dv[eraaccuracy$DVresp16>0] <- 1;
eraaccuracy$item17attempted.dv <- NA; eraaccuracy$item17attempted.dv[eraaccuracy$DVresp17>0] <- 1;
eraaccuracy$item18attempted.dv <- NA; eraaccuracy$item18attempted.dv[eraaccuracy$DVresp18>0] <- 1;
eraaccuracy$item19attempted.dv <- NA; eraaccuracy$item19attempted.dv[eraaccuracy$DVresp19>0] <- 1;
eraaccuracy$item20attempted.dv <- NA; eraaccuracy$item20attempted.dv[eraaccuracy$DVresp20>0] <- 1;
eraaccuracy$item21attempted.dv <- NA; eraaccuracy$item21attempted.dv[eraaccuracy$DVresp21>0] <- 1;
eraaccuracy$item22attempted.dv <- NA; eraaccuracy$item22attempted.dv[eraaccuracy$DVresp22>0] <- 1;
eraaccuracy$item23attempted.dv <- NA; eraaccuracy$item23attempted.dv[eraaccuracy$DVresp23>0] <- 1;
eraaccuracy$item24attempted.dv <- NA; eraaccuracy$item24attempted.dv[eraaccuracy$DVresp24>0] <- 1;

with(eraaccuracy, describe(cbind(item1attempted.dv,item2attempted.dv,item3attempted.dv,item4attempted.dv,item5attempted.dv,item6attempted.dv,item7attempted.dv,item8attempted.dv,item9attempted.dv,item10attempted.dv,item11attempted.dv,item12attempted.dv,item13attempted.dv,item14attempted.dv,item15attempted.dv,item16attempted.dv,item17attempted.dv,item18attempted.dv,item19attempted.dv,item20attempted.dv,item21attempted.dv,item22attempted.dv,item23attempted.dv,item24attempted.dv)))

eraaccuracy$danvatotalattempted<- with(eraaccuracy, (rowSums(cbind(item1attempted.dv,item2attempted.dv,item3attempted.dv,item4attempted.dv,item5attempted.dv,item6attempted.dv,item7attempted.dv,item8attempted.dv,item9attempted.dv,item10attempted.dv,item11attempted.dv,item12attempted.dv,item13attempted.dv,item14attempted.dv,item15attempted.dv,item16attempted.dv,item17attempted.dv,item18attempted.dv,item19attempted.dv,item20attempted.dv,item21attempted.dv,item22attempted.dv,item23attempted.dv,item24attempted.dv), na.rm=TRUE)))
table(eraaccuracy$danvatotalattempted)

era_DANVA_accuracy <- subset(eraaccuracy, danvatotalattempted>11)

with(era_DANVA_accuracy, describe(cbind(danva1,danva2,danva3,danva4,danva5,danva6,danva7,danva8,danva9,danva10,danva11,danva12,danva13,danva14,danva15,danva16,danva17,danva18,danva19,danva20,danva21,danva22,danva23,danva24)))

era_DANVA_accuracy$danvatotal<- with(era_DANVA_accuracy, (rowSums(cbind(danva1,danva2,danva3,danva4,danva5,danva6,danva7,danva8,danva9,danva10,danva11,danva12,danva13,danva14,danva15,danva16,danva17,danva18,danva19,danva20,danva21,danva22,danva23,danva24), na.rm=TRUE)))
era_DANVA_accuracy$danvapercent <- era_DANVA_accuracy$danvatotal/24
with(era_DANVA_accuracy, describe(cbind(danvatotal, danvapercent)))

# Cronbach alpha for the scale #
with(era_DANVA_accuracy, alpha(data.frame(danva1,danva2,danva3,danva4,danva5,danva6,danva7,danva8,danva9,danva10,danva11,danva12,danva13,danva14,danva15,danva16,danva17,danva18,danva19,danva20,danva21,danva22,danva23,danva24), na.rm=TRUE))

# calculate split half reliability #
danva.rel <- with(era_DANVA_accuracy, data.frame(cbind(danva1,danva2,danva3,danva4,danva5,danva6,danva7,danva8,danva9,danva10,danva11,danva12,danva13,danva14,danva15,danva16,danva17,danva18,danva19,danva20,danva21,danva22,danva23,danva24)))
splithalf.r(danva.rel, sims = 1000, graph = TRUE)

# correlate our ERA measure with the DANVA =.80
with (era_DANVA_accuracy, corr.test(cbind(danvatotal, ERAtotal)))

# convert self rating from factor to NUMERIC
era_DANVA_accuracy$DANVAselfrating<- as.numeric(era_DANVA_accuracy$DANVAselfrating)

# correlating EI test scores with self-assessed EI test scores
with(era_DANVA_accuracy, describe(cbind(DANVAselfrating,danvatotal,danvapercent, ertselfrating, ERAtotal, ERApercent)))
with(era_DANVA_accuracy, corr.test(cbind(DANVAselfrating,danvatotal,danvapercent, ertselfrating, ERAtotal, ERApercent)))
